<?php

namespace App\Http\Controllers\Home;

use App\Models\Liveroom;
use App\Models\Member;
use App\Models\Music;
use App\Models\Roomcategroy;
use App\Models\Roomnum;
use Illuminate\Support\Facades\Redis;

class IndexController extends BaseController
{

    public function __construct(Member $member ,Roomcategroy $roomcategroy , Roomnum $roomnum , Music $music , Liveroom $liveroom)
    {
          parent::__construct();
          $this->roomcategroy = $roomcategroy;
          $this->room = $roomnum;
          $this->member = $member;
          $this->music = $music;
          $this->liveroom = $liveroom;
    }

    /**
     * 首页
     */
    public function getIndex(){
         // 获取首页推荐分类
         $where['isp'] = 1;
         $pcate = $this->roomcategroy->getList($where);
         $data = $this->room->indexData($pcate);
         $musicdata = $this->music->getIndexData();
         $user = $this->member->userInit();
         // 随机获取一个正在直播的直播间

         // 获取右侧排行榜数据
         $this->liveroom->getTopData();
         return view('Home.home.index',compact('data','user','musicdata'));
    }

    /**
     * ajax 返回音乐数据
     */
    public function getMusicData(){
         $data = $this->music->getMusicById(request('id'));
         echo json_encode($data);
    }

    /**
     * ajax 获取下一个id
     */
    public function getNextMusicInfo(){
        $data = $this->music->getNextInfo(request('id'));
        echo json_encode($data);
    }
}